package labb3.FileHandling;

import labb3.DVD;
import labb3.Media;

import java.beans.XMLEncoder;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Mikko Puustinen
 * @version 0.1, 2007-okt-14
 */
public class SaveXML implements CollectionSaver {
    private String path;

    //Not implemented
    private SaveXML(String path) {
        this.path = path;
    }

    public void saveCollection(ArrayList<Media> media) throws IOException {
        //XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(path)));
        XMLEncoder encoder = null;
        try {
            encoder = new XMLEncoder(new FileOutputStream(path));
            for (Media m : media) {
                    encoder.writeObject(m);
                    encoder.flush();
                

            }
        } catch (FileNotFoundException e) {
            throw new IOException("File not found");
        } finally {
            if (encoder != null) {
                encoder.close();
            }
        }

    }
}
